package com.yan.demo.method;

import java.util.Random;

public class MethodTest14 {
    public static void main(String[] args) {
        int[] arr = new int[10];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(101) + 1;
        }
        double avg = newArr(arr);
        System.out.println("平均数为:" + avg);

    }

    public static double newArr(int[] arr){
        double sum = 0.0;
        double avg = 0.0;
        int min = arr[0];
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] > max){
                max = arr[i];
            }
            if(arr[i] < min){
                min = arr[i];
            }
            sum += arr[i];
        }
        sum = sum - max - min;
        avg = sum / (arr.length - 2);
        return avg;
    }
}
